package dashboard.constant;

import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import dashboard.dbentity.NetFlowESCityCate;
import dashboard.dbentity.NetFlowFCCityCate;
import dashboard.dbentity.NetFlowHYCityCate;
import dashboard.dbentity.NetFlowZPCityCate;

/**
 * 
 * 数据看板的类别
 * 
 * <p>
 * detailed comment
 * 
 * @author guolu 2015-1-26
 * @see
 * @since 1.0
 */
public enum EnumCate {
	total, zhaopin, fangchan, huangye, ershou, ershouche;
	public static final JSONObject business_CN_Map = JSONObject.fromObject("{'':'总体',total:'总体',zhaopin:'招聘',fangchan:'房产',huangye:'黄页',ershou:'二手',ershouche:'二手车'}");
	
	
	
	/**
	 * 对应表t_common_netflow_board的business_name字段
	 * 
	 * @param cate
	 * @return
	 * @author zhaoxiang 2015-03-06
	 */
	public String getDBName() {
		switch (this) {
		case total:
			return "all";
		case zhaopin:
			return "招聘";
		case fangchan:
			return "房产";
		case huangye:
			return "黄页";
		case ershou:
			return "二手";
		case ershouche:
			return "二手车";
		default:
			return "";
		}
	}

	/**
	 * @return
	 * @author zhaoxiang 2015-1-31
	 */
	public String getCateOneNames() {
		switch (this) {
			case total:
				return "'招聘','房产','黄页','二手','二手车'";
			case zhaopin:
				return "'全职招聘','兼职招聘','找兼职','求职信息'";
			case fangchan:
				return "'租房','二手房','商业房产'";
			case huangye:
				return "'家政服务','商务服务','汽车服务','其他'";
			case ershou:
				return "'二手市场','宠物','车辆买卖与服务'";
			case ershouche:
				return "'二手车'";
			default:
				return "'招聘','黄页','房产','二手','二手车'";
		}
	}

	private static final JSONArray cityOneList = JSONArray.fromObject("['直销城市','渠道城市','北京', '成都', '重庆', '石家庄', '济南', '青岛', '南京', '杭州', '苏州', '无锡', '合肥', '武汉', '郑州', '长沙', '福州', '厦门', '南宁', '哈尔滨', '长春', '太原', '大连', '沈阳', '上海', '天津', '广州', '深圳', '东莞']");
	
	/**流量看板的一级城市下拉列表
	 * @return
	 * @author zhaoxiang 2015-03-26
	 */
	public static List<?> getCityOneList() {
				return cityOneList;
	}
	
	
	/**流量看板的二级类别下拉列表
	 * @return
	 * @author zhaoxiang 2015-03-26
	 */
	public String getCateTwoNames() {
		switch (this) {
			case zhaopin:
				return "'普工/技工','销售','超市/百货/零售','司机','餐饮','人事/行政/后勤','物流/仓储','家政保洁/安保','客服','财务/审计/统计'";
			case fangchan:
				return "'租房','二手房','写字楼','商铺租售/生意转让','出租','新房','厂房/仓库/土地/车位','求租房','短租房/日租房','合租房'";
			case huangye:
				return "'建材','家电维修','保洁清洗','租车','家装服务','二手回收','生活配送','快递','搬家','保姆/月嫂'";
			case ershou:
				return "'二手家具','笔记本电脑','宠物狗','自行车/电动车','花鸟鱼虫','二手摩托车','台式机/配件','二手手机','二手家电'";
			default:
				return "";
		}
	}
	
	/**流量看板的二级类别下拉列表
	 * @return
	 * @author zhaoxiang 2015-03-26
	 */
	public Class<?> getCityCateBeanCls() {
		switch (this) {
			case zhaopin:
				return NetFlowZPCityCate.class;
			case fangchan:
				return NetFlowFCCityCate.class;
			case huangye:
				return NetFlowHYCityCate.class;
			case ershou:
				return NetFlowESCityCate.class;
			default:
				return null;
		}
	}		
	
	/**
	 * @return
	 * @author zhaoxinag 2015-1-26
	 */
	public String getNetFlowCateCon(NetFlowIndex index,String groupBy) {
		switch (this) {
			case total:
				return getCateTotalCon(index, groupBy);
			default:
				return getCateCon(index, groupBy);
			}
	}
	
	//分业务线汇总
	private static final String PATTEN_business_name = "cate1_name='all' AND page_type='%s' AND business_name!='all' GROUP BY %s";
	private static final String PATTEN_business_name_PVVP_UV = "cate1_name='all' AND business_name!='all' AND (page_type='all' OR page_type='detail') GROUP BY %s";
	
	//每个业务线一级重点类别汇总
	private static final String PATTEN_cate = "business_name='%s' AND page_type='%s' AND cate1_name!='all'  GROUP BY %s";
	private static final String PATTEN_cate_PVVP_UV = "business_name='%s' AND (page_type='all' OR page_type='detail') AND cate1_name!='all' GROUP BY %s";

	/**
	 * 获取分业务线流量查询条件
	 * @param cate
	 * @return
	 * @author zhaoxiang 2015-1-31
	 */
	public String getCateTotalCon(NetFlowIndex index,String groupBy) {
		switch (index) {
			case vppv:
				return String.format(PATTEN_business_name, EnumPageType.detail.getDBName(), groupBy);
			case vppvDIVuv:// 既需要详情页算vppv 又需要所有算uv
				return String.format(PATTEN_business_name_PVVP_UV, groupBy);
			case lide_pv:
				return String.format(PATTEN_business_name, EnumPageType.listanddetail.getDBName(), groupBy);
			case lide_uv:
				return String.format(PATTEN_business_name, EnumPageType.listanddetail.getDBName(), groupBy);
			default:// pv uv pvDIVuv 只需要所有
				return String.format(PATTEN_business_name, EnumPageType.total.getDBName(), groupBy);
		}
	}
	
	/**
	 * 获取该业务线重点类别流量查询条件
	 * @param cate
	 * @return
	 * @author zhaoxiang 2015-1-31
	 */
	public String getCateCon(NetFlowIndex index,String groupBy) {
		switch (index) {
		case vppv:
			return String.format(PATTEN_cate, this.getDBName(),EnumPageType.detail.getDBName(), groupBy);
		case vppvDIVuv:// 既需要详情页算vppv 又需要所有算uv
			return String.format(PATTEN_cate_PVVP_UV, this.getDBName(), groupBy);
		case lide_pv:
			return String.format(PATTEN_cate, this.getDBName(), EnumPageType.listanddetail.getDBName(), groupBy);
		case lide_uv:
			return String.format(PATTEN_cate,this.getDBName(), EnumPageType.listanddetail.getDBName(), groupBy);
		default:// pv uv pvDIVuv 只需要所有
			return String.format(PATTEN_cate, this.getDBName(),EnumPageType.total.getDBName(), groupBy);
		}

	}
	

	//每个业务线一级重点类别汇总
	private static final String PATTEN_city_cate2 = "business_name='%s' AND city1_name='%s' AND  cate2_name='%s' AND page_type='%s' GROUP BY %s";
	private static final String PATTEN_city_cate2_vppvDIVuv = "business_name='%s' AND city1_name='%s' AND  cate2_name='%s' AND (page_type='all' OR page_type='detail') GROUP BY %s";
	/**
	 * 获取该业务线 一级城市二级类 流量查询条件
	 * @param cate
	 * @return
	 * @author zhaoxiang 2015-03-26
	 */
	public String getCityCateCon(NetFlowIndex index,String city1, String cate2, String groupBy) {
		switch (index) {
		case vppv:
			return String.format(PATTEN_city_cate2,this.getDBName(),city1, cate2, EnumPageType.detail.getDBName(), groupBy);
		case vppvDIVuv:// 既需要详情页算vppv 又需要所有算uv
			return String.format(PATTEN_city_cate2_vppvDIVuv,this.getDBName(), city1, cate2, groupBy);
		case lide_pv:
			return String.format(PATTEN_city_cate2,this.getDBName(),city1, cate2, EnumPageType.listanddetail.getDBName(), groupBy);
		case lide_uv:
			return String.format(PATTEN_city_cate2,this.getDBName(), city1, cate2, EnumPageType.listanddetail.getDBName(), groupBy);
		default:// pv uv pvDIVuv 只需要所有
			return String.format(PATTEN_city_cate2, this.getDBName(),city1, cate2, EnumPageType.total.getDBName(), groupBy);
		}

	}
}
